<?php
include("include/config.inc.php");
include("include/version.inc.php");
include("include/tables.inc.php");
include("include/funktion.inc.php");




$email = $_POST['email'];
$name = $_POST['name'];
if(!is_numeric($art = $_POST['art'])) $art = 1;

$pruefung = "^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$";

if(!isset($email) OR $email == "" OR !ereg($pruefung,$email))
   {
   eval ("\$meldung = \"".template('kein_email')."\";");
   }
else if($art == "0")
   {
   $abfrage = "SELECT `id` FROM `$emailsdb` WHERE `email` = '$email'";
   $ergebnis = mysql_query($abfrage);

   if(mysql_num_rows($ergebnis))
      {
      $loeschen = "DELETE FROM `$emailsdb` WHERE `email` = '$email'";
      $loesch = mysql_query($loeschen);

      if($loesch)
         {
         send_austragen($email);
         eval ("\$meldung = \"".template('adresse_geloescht')."\";");
         }
      else
         {
         eval ("\$meldung = \"".template('fehler_loeschen')."\";");
         }
      }
   else
      {
      eval ("\$meldung = \"".template('adresse_nicht_vorhanden')."\";");
      }

   }
else //Email Eintragen
   {
   $abfrage = "SELECT `id` FROM `$emailsdb` WHERE `email` = '$email'";
   $ergebnis = mysql_query($abfrage);

   if(mysql_num_rows($ergebnis))
      {
      eval ("\$meldung = \"".template('adresse_vergeben')."\";");
      }
   else
      {
      $eintrag = "INSERT INTO `$emailsdb` (`email`, `name`) VALUES ('$email', '$name')";
      $eintragen = mysql_query($eintrag);
      if($eintragen)
         {
         eval ("\$meldung = \"".template('email_gespeichert')."\";");
         send_eintragen($email,$name);
         }
      else
         {
         eval ("\$meldung = \"".template('fehler_speichern')."\";");
         }
      }
   }


$status_meldung = $meldung;

$url = $config['refresh'];
if($url === "HTTP_REFERER" OR (strstr($url,"|") AND substr($url,0,strpos($url,"|")) === "HTTP_REFERER"))
   {
   $url = $_SERVER["HTTP_REFERER"];

   $urlsuch="#^((http(s)?)://)+"
   ."(localhost|"
   ."[a-z\d\.@_-]*[a-z\d@_-]+\.([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|shop)"
   .")"
   ."[a-z\d@\/\%\#\~\.\?=&,;_-]*$#i";

   if(empty($url) OR !preg_match($urlsuch,$url))
		{
		$url = substr(strchr($config['refresh'],"|"),1);

		if(empty($url))
      	$url = "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"]);
		}
   }


eval ("\$output = \"".template("save")."\";");

echo $output;


?>